
import { useReducer } from 'react';

function counterReducer(state, action) {
  if (action.type === 'increment') {
     return {
      count: state.count + 1
    };
  } else if (action.type === 'decrement') {
    return {
      count: state.count - 1
    };
  }
}
export default  function reducerComponent() {
  const [state, dispatch] = useReducer(counterReducer, {count: 0});
  return(<div>
    <div>{state.count}</div>  
    <button onClick={() => dispatch({type: 'increment'})}>+</button>
    <button onClick={() => dispatch({type: 'decrement'})}>-</button>

  </div>)
}